package com.tarim.wheat.service.impl;

import com.tarim.wheat.mapper.MessageMapper;
import com.tarim.wheat.model.Message;
import com.tarim.wheat.service.MessageService;
import com.tarim.wheat.vo.Criteria;
import com.tarim.wheat.vo.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MessageServiceImpl implements MessageService {
    @Autowired
    MessageMapper messageMapper;

    @Override
    public int insert(Message message) {
        return messageMapper.insert(message);
    }

    @Override
    public PageBean selectByUser(Criteria criteria, PageBean pageBean) {
        criteria.addExtField("pageIndex", (pageBean.getPageIndex() - 1) * pageBean.getPageSize());
        criteria.addExtField("pageSize", pageBean.getPageSize());
        Long count = messageMapper.selectByUserCount(criteria);
        List list = messageMapper.selectByUser(criteria);
        pageBean.setTotalCount(count);
        pageBean.setResultList(list);
        return pageBean;
    }

    @Override
    public int updateForDelete(List list) {
        return messageMapper.updateForDelete(list);
    }
}
